(0) Obligation:

The Runtime Complexity (innermost) of the given CpxTRS could be proven to be BOUNDS(1, n^1).


The TRS R consists of the following rules:

sum(0) → 0
sum(s(x)) → +(sqr(s(x)), sum(x))
sqr(x) → *(x, x)
sum(s(x)) → +(*(s(x), s(x)), sum(x))

Rewrite Strategy: INNERMOST

(1) TrsToWeightedTrsProof (BOTH BOUNDS(ID, ID) transformation)

Transformed TRS to weighted TRS

(2) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, n^1).


The TRS R consists of the following rules:

sum(0) → 0 [1]
sum(s(x)) → +(sqr(s(x)), sum(x)) [1]
sqr(x) → *(x, x) [1]
sum(s(x)) → +(*(s(x), s(x)), sum(x)) [1]

Rewrite Strategy: INNERMOST

(3) TypeInferenceProof (BOTH BOUNDS(ID, ID) transformation)

Infered types.

(4) Obligation:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

sum(0) → 0 [1]
sum(s(x)) → +(sqr(s(x)), sum(x)) [1]
sqr(x) → *(x, x) [1]
sum(s(x)) → +(*(s(x), s(x)), sum(x)) [1]

The TRS has the following type information:
sum :: 0:s:+ → 0:s:+
0 :: 0:s:+
s :: 0:s:+ → 0:s:+
+ :: * → 0:s:+ → 0:s:+
sqr :: 0:s:+ → *
* :: 0:s:+ → 0:s:+ → *

Rewrite Strategy: INNERMOST

(5) CompletionProof (UPPER BOUND(ID) transformation)

The TRS is a completely defined constructor system, as every type has a constant constructor and the following rules were added:

sum(v0) → null_sum [0]

And the following fresh constants:

null_sum, const

(6) Obligation:

Runtime Complexity Weighted TRS where all functions are completely defined. The underlying TRS is:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

sum(0) → 0 [1]
sum(s(x)) → +(sqr(s(x)), sum(x)) [1]
sqr(x) → *(x, x) [1]
sum(s(x)) → +(*(s(x), s(x)), sum(x)) [1]
sum(v0) → null_sum [0]

The TRS has the following type information:
sum :: 0:s:+:null_sum → 0:s:+:null_sum
0 :: 0:s:+:null_sum
s :: 0:s:+:null_sum → 0:s:+:null_sum
+ :: * → 0:s:+:null_sum → 0:s:+:null_sum
sqr :: 0:s:+:null_sum → *
* :: 0:s:+:null_sum → 0:s:+:null_sum → *
null_sum :: 0:s:+:null_sum
const :: *

Rewrite Strategy: INNERMOST

(7) CpxTypedWeightedTrsToRntsProof (UPPER BOUND(ID) transformation)

Transformed the TRS into an over-approximating RNTS by (improved) Size Abstraction.
The constant constructors are abstracted as follows:

0 => 0
null_sum => 0
const => 0

(8) Obligation:

Complexity RNTS consisting of the following rules:

sqr(z) -{ 1 }→ 1 + x + x :|: x >= 0, z = x
sum(z) -{ 1 }→ 0 :|: z = 0
sum(z) -{ 0 }→ 0 :|: v0 >= 0, z = v0
sum(z) -{ 1 }→ 1 + sqr(1 + x) + sum(x) :|: x >= 0, z = 1 + x
sum(z) -{ 1 }→ 1 + (1 + (1 + x) + (1 + x)) + sum(x) :|: x >= 0, z = 1 + x

Only complete derivations are relevant for the runtime complexity.

(9) CompleteCoflocoProof (EQUIVALENT transformation)

Transformed the RNTS (where only complete derivations are relevant) into cost relations for CoFloCo:

eq(start(V),0,[sum(V, Out)],[V >= 0]).
eq(start(V),0,[sqr(V, Out)],[V >= 0]).
eq(sum(V, Out),1,[],[Out = 0,V = 0]).
eq(sum(V, Out),1,[sqr(1 + V1, Ret01),sum(V1, Ret1)],[Out = 1 + Ret01 + Ret1,V1 >= 0,V = 1 + V1]).
eq(sqr(V, Out),1,[],[Out = 1 + 2*V2,V2 >= 0,V = V2]).
eq(sum(V, Out),1,[sum(V3, Ret11)],[Out = 4 + Ret11 + 2*V3,V3 >= 0,V = 1 + V3]).
eq(sum(V, Out),0,[],[Out = 0,V4 >= 0,V = V4]).
input_output_vars(sum(V,Out),[V],[Out]).
input_output_vars(sqr(V,Out),[V],[Out]).

CoFloCo proof output:
Preprocessing Cost Relations
=====================================

#### Computed strongly connected components
0. non_recursive : [sqr/2]
1. recursive : [sum/2]
2. non_recursive : [start/1]

#### Obtained direct recursion through partial evaluation
0. SCC is completely evaluated into other SCCs
1. SCC is partially evaluated into sum/2
2. SCC is partially evaluated into start/1

Control-Flow Refinement of Cost Relations
=====================================

### Specialization of cost equations sum/2
* CE 4 is refined into CE [8]
* CE 7 is refined into CE [9]
* CE 5 is refined into CE [10]
* CE 6 is refined into CE [11]


### Cost equations --> "Loop" of sum/2
* CEs [10,11] --> Loop 4
* CEs [8,9] --> Loop 5

### Ranking functions of CR sum(V,Out)
* RF of phase [4]: [V]

#### Partial ranking functions of CR sum(V,Out)
* Partial RF of phase [4]:
- RF of loop [4:1]:
V


### Specialization of cost equations start/1
* CE 2 is refined into CE [12,13]
* CE 3 is refined into CE [14]


### Cost equations --> "Loop" of start/1
* CEs [12,13,14] --> Loop 6

### Ranking functions of CR start(V)

#### Partial ranking functions of CR start(V)


Computing Bounds
=====================================

#### Cost of chains of sum(V,Out):
* Chain [[4],5]: 2*it(4)+1
Such that:it(4) =< V

with precondition: [V>=1,Out>=2*V+2]

* Chain [5]: 1
with precondition: [Out=0,V>=0]


#### Cost of chains of start(V):
* Chain [6]: 2*s(1)+1
Such that:s(1) =< V

with precondition: [V>=0]


Closed-form bounds of start(V):
-------------------------------------
* Chain [6] with precondition: [V>=0]
- Upper bound: 2*V+1
- Complexity: n

### Maximum cost of start(V): 2*V+1
Asymptotic class: n
* Total analysis performed in 39 ms.

(10) BOUNDS(1, n^1)